<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>工作量计算系统</title>
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta HTTP-EQUIV="expires" CONTENT="0">

    <link rel="Shortcut Icon" href="../images/favicon.ico"/>

    <link rel="stylesheet" href="../src/css/layui.css">
    <script src="../src/layui.js"></script>
    <script src="../js/jquery-3.2.1.js"></script>
    <script src="../js/setting.js"></script>
    <script src="../src/layui.js"></script>
    <script src="../js/des.js"></script>
    <style>
        form {
            padding: 10px;
            margin-right: 10%
        }
    </style>

</head>
<body>
<header>
</header>

<main>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>修改密码</legend>
    </fieldset>
    <div class="layui-row">
        <div class="layui-col-md4">

        </div>
        <div class="layui-col-md4 layui-col-md-offset4">
            <form class="layui-form layui-form-pane1">
                <div class="layui-form-item">
                    <div class="layui-input-block" align="center" style="width: 320px">
                        <input type="text" id="name" name="name" lay-verify="name" placeholder="用户名" autocomplete="true"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" align="center" style="width: 320px">
                        <input type="password" id="oldPsw" name="oldPsw" lay-verify="pass" placeholder="旧密码"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block" align="center" style="width: 320px">
                        <input type="password" id="newPsw" name="newPsw" lay-verify="pass" placeholder="新密码"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" align="center" style="width: 320px">
                        <input type="password" id="surepsw" name="surepsw" lay-verify="surepsw" placeholder="确认密码"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="margin: 35px">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="reg">修改</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</main>


<script>
    layui.use(['form', 'element', 'jquery'], function () {
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
        var form = layui.form;
        var $ = layui.jquery;
        //监听导航点击
        element.on('nav(demo)', function (elem) {
            //console.log(elem)
            layer.msg(elem.text());
        });
        form.verify({
            name: function (value) {
                if (value.length < 5) {
                    return '昵称不低于5位';
                } else if (value.length > 12) {
                    return '昵称过长了'
                }
            }
            , pass: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格']
            , surepsw: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格']
            , email: [/(.+)@(.+)\.(.+)/, "请输入正确邮箱"]
        });
        //监听提交
        form.on('submit(reg)', function (data) {
            if (data.field.newPsw != data.field.surepsw) {
                layer.msg("两次密码不相同");
                return false;
            } else if (data.field.newPsw == data.field.oldPsw) {
                layer.msg("修改的密码不能相同");
                return false;
            }
            var newTable = {
                "name": data.field.name,
                "oldPsw": strEnc(data.field.oldPsw, 'amoxu', 'amoxu', 'amoxu'),
                "newPsw": strEnc(data.field.newPsw, 'amoxu', 'amoxu', 'amoxu')
            };
            $.ajax({
                type: 'post'
                , url: "/user/password"
                , data: newTable
                , dataType: 'json'
                , contentType: 'application/x-www-form-urlencoded;charset=UTF-8'
                , success: function (res) {
                    if (res["status"] == 1) {
                        layer.msg(res['msg']);
                        return false;
                    }
                    layer.msg("修改成功,退出登录生效。");
                }
                , error: function (res) {
                    layer.msg(res['msg']);
                }
            });
            return false;
        });
    });

</script>
</body>
</html>